import 'package:get/get.dart';
import 'package:xinxuan/http/http_util_service.dart';
import 'package:xinxuan/vo/common_vo/common_pagination_vo.dart';
import 'package:xinxuan/vo/gratitudes_vo.dart';

class GratitudeRecordPageController extends GetxController {

  var gratitudesVo = GratitudesVo(
    data: [],
    meta: GratitudesMeta(
      aggregates: Aggregates(
        balance: '0.00',
        received: '0.00'
      ),
      pagination: CommonPagination(
        total: 0,
        currentPage: 1
      )
    )
  ).obs;
  
  @override
  void onReady() {
    getGratitudeRecord();
    super.onReady();
  }

  /// 获取回馈感恩值数据
  getGratitudeRecord() async {
    gratitudesVo.value.meta!.pagination!.currentPage = 1;
    GratitudesVo temp = await HttpUtilService.getGratitudeRecord(page: gratitudesVo.value.meta!.pagination!.currentPage!);
    gratitudesVo.value = temp;
    update();
  }

  /// 加载更多
  onloadGratitudeRecord() async {
    if (gratitudesVo.value.data!.length >= gratitudesVo.value.meta!.pagination!.total!) {
      return;
    }
    gratitudesVo.value.meta!.pagination!.currentPage = gratitudesVo.value.meta!.pagination!.currentPage! + 1;
    GratitudesVo temp = await HttpUtilService.getGratitudeRecord(page: gratitudesVo.value.meta!.pagination!.currentPage!);
    gratitudesVo.value.data!.addAll(temp.data!);
    update();
  }
}